package com.xc.freeapp.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xc.freeapp.dao.DrugdetailDao;
import com.xc.freeapp.dao.dataSource.DBContextHolder;
import com.xc.freeapp.entity.Drugdetail;
import com.xc.freeapp.service.DrugdetailService;

@Service
public class DrugdetailServiceImpl implements DrugdetailService {

	@Autowired
	private DrugdetailDao drugdetailDao;
	
	public Map<String, Object> getList(String durgId) {
		DBContextHolder.switchDataSourceR();//切换数据源
		Drugdetail detail = drugdetailDao.selectByPrimaryKey(Long.parseLong(durgId));
		Map<String, Object> retmap = new HashMap<String, Object>();
		if(detail!=null){
			retmap.put("id", detail.getId());
			retmap.put("chineseName", detail.getChineseName());
			List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
			Map<String, Object> innermap1 = new HashMap<String, Object>();
			innermap1.put("title", "功效主治");
			innermap1.put("content", detail.getEffects());
			Map<String, Object> innermap2 = new HashMap<String, Object>();
			innermap2.put("title", "药理作用");
			innermap2.put("content", detail.getPharmacology());
			Map<String, Object> innermap3 = new HashMap<String, Object>();
			innermap3.put("title", "药物相互作用");
			innermap3.put("content", detail.getInteraction());
			Map<String, Object> innermap4 = new HashMap<String, Object>();
			innermap4.put("title", "化学成分");
			innermap4.put("content", detail.getChemicals());
			Map<String, Object> innermap5 = new HashMap<String, Object>();
			innermap5.put("title", "不良反应");
			innermap5.put("content", detail.getSideEffect());
			Map<String, Object> innermap6 = new HashMap<String, Object>();
			innermap6.put("title", "禁忌症");
			innermap6.put("content", detail.getContrindiction());
			Map<String, Object> innermap7 = new HashMap<String, Object>();
			innermap7.put("title", "注意事项");
			innermap7.put("content", detail.getPrecautions());
			list.add(innermap1);
			list.add(innermap2);
			list.add(innermap3);
			list.add(innermap4);
			list.add(innermap5);
			list.add(innermap6);
			list.add(innermap7);
			retmap.put("contentdata", list);
		}
		return retmap;
	}
	
	  public List<Drugdetail> selectByKeyWord(String keyWord){
		  DBContextHolder.switchDataSourceR();//切换数据源
		return drugdetailDao.selectByKeyWord(keyWord);
		  
	  }

}
